﻿@namespace LinguaNex.Blazor
@inherits LayoutComponentBase

<AntDesign.ProLayout.BasicLayout 
    Logo="@("./logo.svg")"
    MenuData="_menuData">
    <RightContentRender>
    </RightContentRender>
    <ChildContent>
        @Body
    </ChildContent>
    <FooterRender>
        <FooterView Copyright="2021 Ant Design Blazor" Links="Links"></FooterView>
    </FooterRender>
</AntDesign.ProLayout.BasicLayout>
<SettingDrawer />

@code
{
    private readonly MenuDataItem[] _menuData =
    {
        new MenuDataItem
        {
            Path = "/",
            Name = "Project",
            Key = "Project",
            Icon = "home",
        }
    };

    public LinkItem[] Links { get; set; } =
    {
        new LinkItem
        {
            Key = "Ant Design Blazor",
            Title = "Ant Design Blazor",
            Href = "https://antblazor.com",
            BlankTarget = true,
        },
        new LinkItem
        {
            Key = "github",
            Title = (RenderFragment)(@<Icon Type="github" />),
            Href = "https://github.com/fanslead/LinguaNex",
            BlankTarget = true,
        },
        new LinkItem
        {
            Key = "Blazor",
            Title = "Blazor",
            Href = "https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor?WT.mc_id=DT-MVP-5003987",
            BlankTarget = true,
        }
    };
}

<script>
    window.clipboardCopy = {
        copyText: function (text) {
            if (navigator.clipboard && window.isSecureContext) {
                navigator.clipboard.writeText(text).then(function () {
                })
                    .catch(function (error) {
                        alert(error);
                    });
            } else {
                // 创建text area
                const textArea = document.createElement('textarea')
                textArea.value = text
                // 使text area不在viewport，同时设置不可见
                document.body.appendChild(textArea)
                textArea.focus()
                textArea.select()
                return new Promise((res, rej) => {
                    // 执行复制命令并移除文本框
                    document.execCommand('copy') ? res() : rej()
                    textArea.remove()
                })
            }
        }
    };

      window.downloadFileFromStream = async (fileName, contentStreamReference) => {
        const arrayBuffer = await contentStreamReference.arrayBuffer();
        const blob = new Blob([arrayBuffer]);
        const url = URL.createObjectURL(blob);
        const anchorElement = document.createElement('a');
        anchorElement.href = url;
        anchorElement.download = fileName ?? '';
        anchorElement.click();
        anchorElement.remove();
        URL.revokeObjectURL(url);
      }
</script>